﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using System.Linq;
using WPFExcelReport.Helpers;
using System.Windows.Input;
using System.Windows.Controls;
namespace WPFExcelReport
{
    /// <summary>
    /// 专用于布卷剪布
    /// </summary>
    public partial class UIWVWB25: UIWBBST
    {
       public TDRAUFTR cDR
        {
            get
            {
                return (TDRAUFTR)this.FindName("cDR");
            }
        }
        public UIWVWB25()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VWBBST();
            this.DataContext = MV; 
        }
        public override void OnRWAUFChg(string value)
        {
            TMV.WBDLOAD(value);
            TBWB = null;
            TBWB = TBMain;
            base.OnRWAUFChg(value);
        }
        public override void OnEXAUFChg(string vlaue)
        {
            if (!IsCanLoad)
                return;
            TMV.ABWBDLOAD(vlaue);
            TBWB = null;
            TBWB = TBMain;
            base.OnEXAUFChg(vlaue);
        }
        public override void PrintCommand(object sender, RoutedEventArgs e)
        {
            DataTable tb = TBMain.Clone();
            if (((DataGrid)master).SelectedItems.Count > 0)
            {
                foreach (var item in ((DataGrid)master).SelectedItems)
                {
                    if (!item.GetType().ToString().Contains("DataRowView")) continue;

                    DataRow dwItem = ((System.Data.DataRowView)item).Row;
                    DataRow _dwWB = tb.Rows.Add();
                    _dwWB.ItemArray = dwItem.ItemArray; 
                }
            }
            else
            {
                tb = TBMain.Copy();
            }
            foreach (DataRow _dwWB in tb.Rows)
            {
                _dwWB["REMARK"] = INFO;
            }
            tb.TableName = TMV.TableName;
            DataSet Set = new DataSet();
            DataRow dwtb = tb.Rows[0];
            DataRow dwData = TMV.VVA.TBMain.NewRow();
            dwData["VAAMANDANT"] = app.Mandant;
            dwData["VAAART"] = dwtb["WBBART"].ToString().Trim();
            Set.Merge(TMV.VVA.QVA10(dwData));
            dwData = TMV.VABP.TBMain.NewRow();
            dwData["ABPMANDANT"] = app.Mandant; 
            dwData["ABPAUFKRS"] = ORDERNUM.Substring(0,2).ToString();
            dwData["ABPAUFLFD"] = ORDERNUM.Substring(2,6).ToString();
            dwData["ABPAUFPOS"] = ORDERNUM.Substring(8,3).ToString();
            Set.Merge(TMV.VABP.QABP50(dwData));
            Set.Merge(tb);           
            cDR.PRINT(Set);
            base.PrintCommand(sender, e);
            
        }
        #region ==ROLLS===========
        public static readonly DependencyProperty ROLLSProperty = DependencyProperty.Register("ROLLS",
            typeof(double), typeof(UIWVWB25),
            new FrameworkPropertyMetadata(0.0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnROLLSChanged));
        public double ROLLS
        {
            get
            {
                return (double)GetValue(ROLLSProperty);
            }
            set
            {
                SetValue(ROLLSProperty, value);
            }
        }
        private static void OnROLLSChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWVWB25;
            if (src != null)
            {
                src.ROLLS = (double)e.NewValue;
            }
        }
        #endregion

        #region ==BZ===========
        public static readonly DependencyProperty BZProperty = DependencyProperty.Register("BZ",
            typeof(string), typeof(UIWVWB25),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnBZChanged));
        public string BZ
        {
            get
            {
                return (string)GetValue(BZProperty);
            }
            set
            {
                SetValue(BZProperty, value);
                
            }
        }
        private static void OnBZChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as UIWVWB25;
            if (src != null)
            {
                src.BZ = (string)e.NewValue;
                src.OnBZChg();
            }
        }
        public virtual void OnBZChg()
        { }
        #endregion
        

    }
}
